<?php

namespace support;

class FileStore
{
    public function upload($request, $allowedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'doc', 'pdf', 'docx', 'txt', 'psd', 'ai', 'cdr', 'fjr', 'd4', 'r20', 'xml'])
    {
        $file = $request->file('file');

        $extension = strtolower($file->getUploadExtension());

        print_r([$extension, $allowedExtensions]);

        if (!in_array($extension, $allowedExtensions)) {
            throw new \Exception('不允许的文件扩展名');
        }

        $relativePath = '/userUpload/' . microtime(true) * 1000 . '.' . $extension;
        $file->move(public_path() . $relativePath);

        return getenv('APP_URL') . $relativePath;
    }
}